package xujiwen.transport.servlet;

import xujiwen.transport.bean.ChargeSTD;
import xujiwen.transport.Mgr.ChargeSTDMgr;
import java.text.SimpleDateFormat;
import java.util.Date;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class for Servlet: Register
 * 
 */
public class ModifSTD extends javax.servlet.http.HttpServlet implements
		javax.servlet.Servlet {
	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public ModifSTD() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	@Override
	protected void doGet(final HttpServletRequest request,
			final HttpServletResponse response) throws ServletException,
			IOException {
		// TODO Auto-generated method stub
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	@Override
	protected void doPost(final HttpServletRequest request,
			final HttpServletResponse response) throws ServletException,
			IOException {
		/*final HttpSession session = request.getSession();
		final User user = (User)session.getAttribute("user");
		if (user==null){
			response.sendRedirect("login.jsp");
			System.out.println("未登陆");
			return ;
		}*/
		ChargeSTDMgr cm = new ChargeSTDMgr();
		// 指明编码
		//request.setCharacterEncoding("utf-8"); 
		
		//System.out.println(password + "\t" + email + "\t");
		try {
			final int csid = Integer.parseInt(request.getParameter("csid"));
			final int carclass = Integer.parseInt(request.getParameter("carclass"));
			final double price = Double.parseDouble(request.getParameter("price"));
			
			final ChargeSTD std = new ChargeSTD();
			std.setCsid(csid);
			std.setCarClass(carclass);
			std.setPrice(price);
			cm.Update(std);
			System.out.println("修改收费标准成功");
		} catch(final NumberFormatException nfex){
			//response.sendRedirect("err.jsp");
			System.out.println("提交错误");			
			return ;
		}
		response.sendRedirect("admin/chargeSTDMgr.jsp");
	}
}